import http from "@/utils/http";
import type * as Dept from "./type";

/**
 * @desc 部门树
 */
export const deptTree = (deptName?: string) => {
  return http.get<Dept.DeptTree[]>("/sass/dept/tree", { deptName });
};

/**
 * @desc 新增部门
 */
export const addDept = (data: Dept.DeptInfo) => {
  return http.post("/sass/dept/add", data);
};

/**
 * @desc 编辑部门
 */
export const editDept = (data: Dept.DeptInfo, deptId: string) => {
  return http.put(`/sass/dept/update/${deptId}`, data);
};

/**
 * @desc 获取部门详情
 */
export const deptDetail = (deptId: string) => {
  return http.get<Dept.DeptTree>(`/sass/dept/detail/${deptId}`);
}

/**
 * @desc 删除部门
 */
export const deleteDept = (deptId: string | number) => {
  return http.deleteMethod(`/sass/dept/delete/${deptId}`);
};

/**
 * @desc 根据部门id,加载部门人员
 */
export const deptPersonnelList = (data: Dept.PersonnelListParams) => {
  return http.get<Dept.PersonnelListData>("/sass/dept/user/pageList", data);
};

/**
 * @desc 移除用户——部门
 */
// export const removeDeptUser = (userId: string, deptId: string) => {
//   return http.deleteMethod(`/dept/delete/${deptId}/${userId}`);
// };

/**
 * @desc 移除用户——组织架构
 */
export const removeDeptUser = (userId: string) => {
  return http.deleteMethod(`/sass/user/delete/${userId}`);
};

/**
 * 批量移除用户——组织架构
 * @param userIds
 */
export const batchRemoveDeptUser = (userIds:string[]) => {
  return http.post(`/sass/user/deleteUserList`,userIds);
};

/**
 * @desc 获取用户部门详情
 */
export const userDeptDetail = (userId:string) => {
  return http.get<Dept.UserDeptDetail>(`/sass/dept/select/${userId}`);
};

/**
 * @desc 保存用户部门
 */
type saveUserDeptType = {
  deptIds:string[],
  mainDeptId:string
}
export const saveUserDept = (userId:string, data:saveUserDeptType) => {
  return http.post(`/sass/dept/saveUserDept/${userId}`, data);
};

/**
 * @desc 下载人员导入模板
 */
export const userImportTemplate = () => {
  return http.post<BlobPart>("/sass/dept/importTemplate", {},{
    responseType: "blob",
  });
};


